package com.syh.jn.scm.infrastructure.repository.impl.downstream.base;

import cn.redscarf.commons.util.bean.ExtBeanUtils;
import com.syh.core.ddd.infrastructure.repository.AbstractAggregateRepository;
import com.syh.jn.scm.domain.downstream.entity.base.DownBusinessEntityExtGoodsInfo;
import com.syh.jn.scm.domain.downstream.repository.base.DownBusinessEntityExtGoodsInfoRepository;
import com.syh.jn.scm.dto.downstream.base.DownBusinessEntityExtGoodsInfoVo;
import com.syh.jn.scm.infrastructure.repository.model.base.BusinessEntityExtGoodsInfoModel;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class DownBusinessEntityExtGoodsInfoRepositoryImpl extends AbstractAggregateRepository<DownBusinessEntityExtGoodsInfo, BusinessEntityExtGoodsInfoModel, Long> implements DownBusinessEntityExtGoodsInfoRepository {
    @Override
    public DownBusinessEntityExtGoodsInfoVo getCodeByGoodsId(Long id,Long businessId) {
			StringBuffer hql = new StringBuffer();
			hql.append("from BusinessEntityExtGoodsInfoModel model where model.goodsId = ? and model.businessEntityId = ?");
			List<BusinessEntityExtGoodsInfoModel> codeModelList = (List<BusinessEntityExtGoodsInfoModel>) this.hibernateTemplate.find(hql.toString(), new Object[]{id, businessId});
			List<DownBusinessEntityExtGoodsInfoVo> codeVoList = new ArrayList<>();
			codeModelList.stream().forEach(codeModel -> {
				DownBusinessEntityExtGoodsInfoVo extGoodsInfoVo = new DownBusinessEntityExtGoodsInfoVo();
				ExtBeanUtils.copyProperties(codeModel, extGoodsInfoVo, false);
				codeVoList.add(extGoodsInfoVo);
			});
			if (codeVoList.size() != 0) {
				return codeVoList.get(0);
			} else {
				return null;
			}
    }
}
